package com.zf.generator.templates;

import com.zf.generator.bean.*;


public class ServiceTemplate
{
  protected static String nl;
  public static synchronized ServiceTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    ServiceTemplate result = new ServiceTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import javax.annotation.Resource;" + NL + "" + NL + "import ";
  protected final String TEXT_3 = ".";
  protected final String TEXT_4 = ";" + NL + "import org.slave4j.orm.hibernate.BaseDao;" + NL + "import org.slave4j.orm.hibernate.BaseService;" + NL + "import org.springframework.stereotype.Service;" + NL + "import org.springframework.transaction.annotation.Transactional;" + NL + "" + NL + "@Service" + NL + "@Transactional" + NL + "public class ";
  protected final String TEXT_5 = " extends BaseService<";
  protected final String TEXT_6 = ">" + NL + "{" + NL + "\t@Override" + NL + "\t@Resource(name=\"";
  protected final String TEXT_7 = "\")" + NL + "\tpublic void setBaseDao(BaseDao<";
  protected final String TEXT_8 = "> baseDao)" + NL + "\t{" + NL + "\t\tthis.baseDao = baseDao;" + NL + "\t}" + NL + "}";
  protected final String TEXT_9 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
	JavaTemplateArgs args = (JavaTemplateArgs)argument;

    stringBuffer.append(TEXT_1);
    stringBuffer.append(args.getPackageName());
    stringBuffer.append(TEXT_2);
    stringBuffer.append(args.getPackageNameInfo().getEntityPackageName());
    stringBuffer.append(TEXT_3);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(args.getClassName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(args.getClassNameInfo().getDaoObjectName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(TEXT_9);
    return stringBuffer.toString();
  }
}
